

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>dynamic_rest.conf &mdash; Dynamic REST 1.3.15 documentation</title>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  

  

  
    <link rel="top" title="Dynamic REST 1.3.15 documentation" href="../../index.html"/>
        <link rel="up" title="Module code" href="../index.html"/> 

  
  <script src="../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../index.html" class="icon icon-home"> Dynamic REST
          

          
          </a>

          
            
            
              <div class="version">
                1.3.15
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
                <p class="caption"><span class="caption-text">Contents</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../tutorial.html">Dynamic REST Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dynamic_rest.html">dynamic_rest package</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../../index.html">Dynamic REST</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          





<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../../index.html">Docs</a> &raquo;</li>
      
          <li><a href="../index.html">Module code</a> &raquo;</li>
      
    <li>dynamic_rest.conf</li>
      <li class="wy-breadcrumbs-aside">
        
          
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for dynamic_rest.conf</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">django.conf</span> <span class="kn">import</span> <span class="n">settings</span> <span class="k">as</span> <span class="n">django_settings</span>
<span class="kn">from</span> <span class="nn">django.test.signals</span> <span class="kn">import</span> <span class="n">setting_changed</span>

<span class="n">DYNAMIC_REST</span> <span class="o">=</span> <span class="p">{</span>
    <span class="c1"># DEBUG: enable/disable internal debugging</span>
    <span class="s1">&#39;DEBUG&#39;</span><span class="p">:</span> <span class="bp">False</span><span class="p">,</span>

    <span class="c1"># ENABLE_BROWSABLE_API: enable/disable the browsable API.</span>
    <span class="c1"># It can be useful to disable it in production.</span>
    <span class="s1">&#39;ENABLE_BROWSABLE_API&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span>

    <span class="c1"># ENABLE_LINKS: enable/disable relationship links</span>
    <span class="s1">&#39;ENABLE_LINKS&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span>

    <span class="c1"># ENABLE_SERIALIZER_CACHE: enable/disable caching of related serializers</span>
    <span class="s1">&#39;ENABLE_SERIALIZER_CACHE&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span>

    <span class="c1"># ENABLE_SERIALIZER_OPTIMIZATIONS: enable/disable representation speedups</span>
    <span class="s1">&#39;ENABLE_SERIALIZER_OPTIMIZATIONS&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span>

    <span class="c1"># ENABLE_BULK_PARTIAL_CREATION: enable/disable partial creation in bulk</span>
    <span class="s1">&#39;ENABLE_BULK_PARTIAL_CREATION&#39;</span><span class="p">:</span> <span class="bp">False</span><span class="p">,</span>

    <span class="c1"># ENABLE_BULK_UPDATE: enable/disable update in bulk</span>
    <span class="s1">&#39;ENABLE_BULK_UPDATE&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span>

    <span class="c1"># MAX_PAGE_SIZE: global setting for max page size.</span>
    <span class="c1"># Can be overriden at the viewset level.</span>
    <span class="s1">&#39;MAX_PAGE_SIZE&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>

    <span class="c1"># PAGE_QUERY_PARAM: global setting for the pagination query parameter.</span>
    <span class="c1"># Can be overriden at the viewset level.</span>
    <span class="s1">&#39;PAGE_QUERY_PARAM&#39;</span><span class="p">:</span> <span class="s1">&#39;page&#39;</span><span class="p">,</span>

    <span class="c1"># PAGE_SIZE: global setting for page size.</span>
    <span class="c1"># Can be overriden at the viewset level.</span>
    <span class="s1">&#39;PAGE_SIZE&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>

    <span class="c1"># PAGE_SIZE_QUERY_PARAM: global setting for the page size query parameter.</span>
    <span class="c1"># Can be overriden at the viewset level.</span>
    <span class="s1">&#39;PAGE_SIZE_QUERY_PARAM&#39;</span><span class="p">:</span> <span class="s1">&#39;per_page&#39;</span><span class="p">,</span>

    <span class="c1"># ADDITIONAL_PRIMARY_RESOURCE_PREFIX: String to prefix additional</span>
    <span class="c1"># instances of the primary resource when sideloading.</span>
    <span class="s1">&#39;ADDITIONAL_PRIMARY_RESOURCE_PREFIX&#39;</span><span class="p">:</span> <span class="s1">&#39;+&#39;</span>
<span class="p">}</span>


<div class="viewcode-block" id="Settings"><a class="viewcode-back" href="../../dynamic_rest.html#dynamic_rest.conf.Settings">[docs]</a><span class="k">class</span> <span class="nc">Settings</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span></div>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">defaults</span><span class="p">,</span> <span class="n">settings</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">defaults</span> <span class="o">=</span> <span class="n">defaults</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">keys</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">defaults</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_reload</span><span class="p">(</span><span class="nb">getattr</span><span class="p">(</span><span class="n">settings</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="p">{}))</span>

        <span class="n">setting_changed</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_settings_changed</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_reload</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Reload settings after a change.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">settings</span> <span class="o">=</span> <span class="n">value</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span> <span class="o">=</span> <span class="p">{}</span>

    <span class="k">def</span> <span class="nf">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attr</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get a setting.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">attr</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">:</span>

            <span class="k">if</span> <span class="n">attr</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">keys</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="s2">&quot;Invalid API setting: &#39;</span><span class="si">%s</span><span class="s2">&#39;&quot;</span> <span class="o">%</span> <span class="n">attr</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">attr</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">settings</span><span class="p">:</span>
                <span class="n">val</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">settings</span><span class="p">[</span><span class="n">attr</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">val</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">defaults</span><span class="p">[</span><span class="n">attr</span><span class="p">]</span>

            <span class="c1"># Cache the result</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">[</span><span class="n">attr</span><span class="p">]</span> <span class="o">=</span> <span class="n">val</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">[</span><span class="n">attr</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">_settings_changed</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Handle changes to core settings.&quot;&quot;&quot;</span>
        <span class="n">setting</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;setting&#39;</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;value&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">setting</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_reload</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>


<span class="n">settings</span> <span class="o">=</span> <span class="n">Settings</span><span class="p">(</span><span class="s1">&#39;DYNAMIC_REST&#39;</span><span class="p">,</span> <span class="n">DYNAMIC_REST</span><span class="p">,</span> <span class="n">django_settings</span><span class="p">)</span>
</pre></div>

           </div>
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2016, ant@altschool.com, ryo@altschool.com.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../',
            VERSION:'1.3.15',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="../../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>